﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Manager;
using System.Data;
using System.Data.SqlClient;
using Model;
namespace HealthSystem
{
    public partial class BatchPermit : System.Web.UI.Page
    {
        HW_SchoolManager manager = new HW_SchoolManager();
        protected void Page_Load(object sender, EventArgs e)
        {
            GetPermitSchool();
            Response.Write("全部学校授权成功");
        }
        private void GetPermitSchool()
        {
            string sql = "select * from HW_School where permit='true'";
            SqlConnection cnn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["HealthServices"].ToString());
            DataSet ds = new DataSet();
            if (cnn.State == ConnectionState.Closed)
                cnn.Open();
            SqlDataAdapter sda = new SqlDataAdapter(sql, cnn);
            sda.Fill(ds);
            HW_School school=null;
            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                try
                {
                    school = new HW_School();
                    school.SchoollCode = ds.Tables[0].Rows[i]["schoollcode"].ToString();
                    school.Permit = true;
                    school.Name = ds.Tables[0].Rows[i]["Name"].ToString();
                    manager.Permit(school);
                }
                catch (Exception ex)
                {
                    Response.Write(ex.Message);
                    Response.Write(school.SchoollCode + school.Name + "出错");
                }
            }
        }
    }
}